﻿using System;
using GC_VKMD.MusicDownloaderClient.Abstractions.Interfaces.Helpers;
using GC_VKMD.MusicDownloaderClient.Enums;
using NLog;

namespace GC_VKMD.MusicDownloaderClient.Helpers
{
	public class NLogLogger : ILogger
	{
		#region Variables

		private readonly Logger _logger;

		private readonly bool _isLogProcessInfoMessages;
		private readonly bool _isLogWarning;
		private readonly bool _isLogErrors;

		#endregion

		#region Constructors

		public NLogLogger(bool isLogProcessInfoMessages, bool isLogWarning, bool isLogErrors)
		{
			_isLogErrors = isLogErrors;
			_isLogProcessInfoMessages = isLogProcessInfoMessages;
			_isLogWarning = isLogWarning;

			_logger = LogManager.GetCurrentClassLogger();
		}

		#endregion

		#region ILogger Members

		public void LoggingMessage(string message, LoggerMessageType messageType)
		{
			switch (messageType)
			{
				case LoggerMessageType.Info:
					if (_isLogProcessInfoMessages)
						_logger.Trace(message);
					break;

				case LoggerMessageType.Trace:
					if (_isLogProcessInfoMessages)
						_logger.Trace(message);
					break;

				case LoggerMessageType.Warning:
					if (_isLogWarning)
						_logger.Warn(message);
					break;

				default:
					throw new NotImplementedException(string.Format("not implemented message type"));
			}
		}

		public void LoggingExceptionMessage(Exception exception)
		{
			if (_isLogErrors)
				_logger.Error(exception.Message, exception);
		}

		#endregion
	}
}
